﻿@using HXDNB.Model
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <form action="@Url.Action("List", "Article", new { MeunID = Request.QueryString["MeunID"] })" method="post">
                <div class="widget-title">
                    <span class="icon"><i class="icon-th"></i></span>
                    <h5>
                        文章信息列表</h5>
                </div>
                <div class="widget-content">
                    <a href="@Url.Action("Info", "Article")" class="btn btn-success">添 加</a>
                    <input type="button" value="批量删除" class="btn btn-danger" onclick="DelArticles()" />
                    <input type="text" name="title" class="span3" style="margin: 0px 15px 0px 0px;" placeholder="文章标题" value="@Request.Form["title"]" />
                    <button type="submit" class="btn btn-info" onclick="return Search();">
                        搜 索</button>
                </div>
                <div class="widget-content">
                    <table class="table table-bordered table-striped with-check">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="title-table-checkbox" name="title-table-checkbox" />
                                </th>
                                <th>
                                    标题
                                </th>
                                <th>
                                    所属栏目
                                </th>
                                <th>
                                    最后更新时间
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th>
                                    缩略图
                                </th>
                                <th>
                                    发布状态
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (ArticleListModel item in ViewBag.PagList.DataList)
                            {
                                <tr>
                                    <td>
                                        <input type="checkbox" name="ArticleID" value="@item.ID" />
                                    </td>
                                    <td>
                                        @Html.Raw(item.Title)
                                    </td>
                                    <td>
                                        @item.MeunName
                                    </td>
                                    <td>
                                        @item.UpdateTime
                                    </td>
                                    <td>
                                        @item.CreateTime
                                    </td>
                                    <td style="text-align: center">
                                        @if (item.Thumbnail != null)
                                        {
                                            <img src="@Url.Content(item.Thumbnail.Replace("img/", "~/Upload/"))" width="50" height="50" />
                                        }
                                    </td>
                                    <td style="text-align: center">
                                        @if (@item.IsRelease == "N")
                                        {
                                            <span class="badge badge-important">待发布</span>                                            
                                        }
                                        else
                                        {
                                            <span class="badge badge-success">已发布</span>                                            
                                        }
                                    </td>
                                    <td style="text-align: center">
                                        <a class="btn btn-primary btn-mini" href="@Url.Action("Info", "Article", new { id = item.ID })">
                                            编 辑 </a>
                                        <input  type="button" value=" 删 除 " class="btn btn-danger btn-mini" onclick="DelArticle(@item.ID)" />
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                    @Html.Partial("_Paging")
                </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //删除单个文章
    function DelArticle(id) {
        if (confirm("确认删除？")) {
            $("#LoadingBox").show();
            $.post('@Url.Action("DelArticle", "Article")', "id=" + id, function (d) {
                $("#LoadingBox").hide();
                //刷新页面，页码不变
                $("form").submit();
            })
        }
    }
    //批量删除文章
    function DelArticles() {
        var obj = $("input:checkbox[name='ArticleID']:checked");
        if (obj.length == 0) { alert("请至少选择一条数据！"); return; }
        var ids = ""; obj.each(function () { ids += $(this).val() + ","; });
        if (confirm("确认删除" + obj.length + "条数据？")) {
            $("#LoadingBox").show();
            $.post('@Url.Action("DelArticle", "Article")', "id=" + ids, function (d) {
                $("#LoadingBox").hide();
                //刷新页面，页码变为第一页
                $('#PageIndex').val(1);
                $("form").submit();
            })
        }
    }
</script>
